/** 在CtlGridPage.ts 里面有关于点击分页按钮时候设置 GridRefreshMode **/
import {CSSProperties} from "react";
import {DataComponentProp, DataComponentState} from "../../datasource";
import {NamePath} from "rc-field-form/lib/interface";
import Grid from "./grid";
import {Column, ColumnApi, GridApi, RowNode} from "ag-grid-community";

export enum GridRefreshMode {
    refreshRows,
    refreshWithFilter,
    refreshAndClearFilter
}

export type GridSelectCondition = ((row: any) => boolean) | string

export interface GridVJsonProp {
    style?: CSSProperties
    toolbarStyle?: CSSProperties
    gridStyle?: CSSProperties
    title?: string
    toolbar: any[]
    fullscreen?: boolean
    height?: 'auto' | 'flex' | number

    /**
     * 允许勾选
     */
    checkbox?: boolean

    /**
     * 允许过滤
     */
    filterable: boolean

    /**
     * 绑定选中行的实体属性路径
     */
    bindSelected: string

    /**
     * 是否隐藏整个工具条
     */
    hideToolbar: boolean

    /**
     * 隐藏常规工具条上的间隔符
     */
    hideToolbarDivider: boolean

    /**
     * 隐藏"刷新"按钮
     */
    hideRefreshButton: boolean

    /**
     * 隐藏"导出"按钮
     */
    hideExportButton: boolean

    /**
     * 隐藏"自动适应宽度"按钮
     */
    hideAutoFitButton: boolean

    /**
     * 隐藏"最大宽度"按钮
     */
    hideAutoSizeButton: boolean

    /**
     * 隐藏"列设置"按钮
     */
    hideColumnSettingButton: boolean

    /**
     * 隐藏"全屏"按钮
     */
    hideFullScreenButton: boolean

    ff?: number
    width?: string | number
    columns?: [any]
    ctl: any
    showRowNumber?: boolean
    showHeader?:boolean
    pagination?: boolean
    paginationOption?: {
        defaultPageSize?: number
        pageSizeOptions?: string[]
        showSizeChanger?: boolean
        showQuickJumper?: boolean
    }
    refreshMode: GridRefreshMode
    onRowDblClick?: (sender: Grid, data: any) => void
    onCellClicked?: (sender: Grid, data: any) => void
    onKeyDown?: (sender: Grid, e: any) => void
    onRowSelect?: (sender: Grid, data: any) => void
    onCellEditingStopped?: (sender: Grid, data: any) => void
}

export interface GridVJsonDataProp extends GridVJsonProp, DataComponentProp<Grid> {
    formItemName: NamePath
}

export interface GridState extends DataComponentState {
    columnHiddenMenuVisible: boolean
}

export interface IGridCellRenderParam {
    value: any
    data: any
    rowIndex: number
    eGridCell: HTMLElement
    eParentOfValue: HTMLElement
    column: Column
    setValue: (v: any) => void
    getValue: () => any
    formatValue: () => any
    refreshCell: () => void
    node: RowNode
    api: GridApi
    columnApi: ColumnApi
}